package org.web.hello.dubbomarket.server.config;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.web.base.domain.config.GlobalString2DateConvert;

import java.text.SimpleDateFormat;

@Configuration("dubboMarketServerJacksonConfig")
public class JacksonConfig {

    @Bean("dubboMarketServerObjectMapper")
    public ObjectMapper objectMapper() {
        ObjectMapper objectMapper = new ObjectMapper();
        // 不输出为 null 的属性
        objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
        objectMapper.registerModule(new JavaTimeModule()); // 支持 java.time 包中的日期和时间类型
        objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"));
        return objectMapper;
    }

    @Bean("dubboMarketServerString2DateConvert")
    public GlobalString2DateConvert getGlobalString2DateConvert() {
        return new GlobalString2DateConvert();
    }

}